<?php

include_once "function_xml_basic.php";

$root_path = "/MINI/RESOURCES/OBJECTS/SERVICECLASS";

function GetXmlServiceObjectByName($name)
{
	$ret_array = GetXmlServiceObjectList();
    
        foreach ($ret_array as $ret)
        {   
                if ($ret['Name'] == $name)
                        return $ret;
        }   
        return NULL;

}

function GetXmlServiceObjectList()
{
	global $root_path;
	$query_string = $root_path. "/ATOM/OBJECT";
	$key_array = array('Name', 'ObjectType', 'Protocol', 'IcmpType', 'Type',
			   'DstStartPort', 'DstEndPort', 'SrcStartPort','SrcEndPort');
	return GetAttributList($query_string, $key_array);
}

function GetProtocolNameByNumber($number)
{
	switch ($number)
	{
	case 1:
		return "ICMP";
	case 6:
		return "TCP";
	case 17:
		return "UDP";
	default:
		return $number;
	}
}

function GetXmlServiceObjcetNameList()
{
	$name_list = array();
	$temp_array = GetXmlServiceObjectList();
	
	$i = 0;
	foreach ($temp_array as $tmp)
	{
		$name_list[$i ++] = $tmp['Name'];
	}
	return $name_list;
}

function GetXmlServiceObjectContentList($name)
{
	$object = GetXmlServiceGroupByName($name);
	$tmp_string = $object['ObjectList'];
	$list = explode(',', $tmp_string);
	#foreach ($list as $i)
	#	print "[". $i. "]\n";
	return $list;
}

function DelXmlSpecialOneServiceObject($name)
{
	global $root_path;

	$query_string = $root_path. "/ATOM/OBJECT[@Name='". $name. "']";
	DelSpecialNode($query_string);
}

function DelXmlAllServiceObject()
{
	global $root_path;
	$query_string = $root_path. "/ATOM/OBJECT[@ObjectType='1']";
	DelSpecialNode($query_string);
}

function AppendXmlServiceObject($in_array)
{
	global $root_path;
        $node_name = "OBJECT";
	$query_string = $root_path. "/ATOM";
	$in_array['ObjectType'] = "1";
	$in_array['Type'] = "1";
	AppendAllAttrOfNode($query_string, $node_name, $in_array);
}

function SetXmlServiceObject($in_array)
{
	global $root_path;
	$name = $in_array['Name'];
	$in_array['ObjectType'] = "1";
	$query_string = $root_path. "/ATOM/OBJECT[@Name='". $name. "']";
	EditAllAttrOfNode($query_string, $in_array);
}

function GetXmlServiceGroupByName($name)
{
	$ret_array = GetXmlServiceGroupList();
    
        foreach ($ret_array as $ret)
        {   
                if ($ret['Name'] == $name)
                        return $ret;
        }   
        return NULL;

}

function GetXmlServiceGroupList()
{
	global $root_path;
	$query_string = $root_path. "/GROUPS/GROUP";
	$key_array = array('Name', 'ObjectList', 'ObjectType', 'Type');
	return GetAttributList($query_string, $key_array);
}

function SetXmlServiceGroup($in_array)
{
	global $root_path;
	$in_array['ObjectType'] = "1";
	$query_string = $root_path. "/GROUPS/GROUP[@Name='". $in_array['Name']. "']";
	EditAllAttrOfNode($query_string, $in_array);
}

function DelXmlSpecialOneServiceGroup($name)
{
	global $root_path;

	$query_string = $root_path. "/GROUPS/GROUP[@Name='". $name. "']";
	DelSpecialNode($query_string);
}

function DelXmlAllServiceGroup()
{
	global $root_path;
	$query_string = $root_path. "/GROUPS/GROUP";
	DelSpecialNode($query_string);
}

function AppendXmlServiceGroup($in_array)
{
	global $root_path;
        $node_name = "GROUP";
	$query_string = $root_path. "/GROUPS";
	$in_array['ObjectType'] = "1";
	$in_array['Type'] = "0";
	AppendAllAttrOfNode($query_string, $node_name, $in_array);
}
?>
